package com.mls.fivedistrict.controller.backend;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mls.fivedistrict.common.PageFilter;
import com.mls.fivedistrict.common.RequestHolder;
import com.mls.fivedistrict.common.ServiceResponse;
import com.mls.fivedistrict.controller.BaseController;
import com.mls.fivedistrict.server.NewsReadReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 新闻阅读报表 前端控制器
 * </p>
 * @author Five Team
 * @since 2018-06-12
 */
@RestController("backendNewsReadReportController")
@RequestMapping("/api/manager")
public class NewsReadReportController extends BaseController {
    @Autowired
    NewsReadReportService newsReadReportService;

    /**
     * 后台阅读报表
     * @return
     */
    @GetMapping("/v1/newsReadReports/{newsId}")
    public ServiceResponse getNewsReadReports(@PathVariable Long newsId){
        PageFilter pageFilter = RequestHolder.getPageFilter();
        PageHelper.startPage(pageFilter.getPageNum(),pageFilter.getPageSize());
        Wrapper wrapper = pageFilter.getWrapper();
        if(null==wrapper){
            wrapper=Condition.create();
        }
        wrapper.eq("news_id",newsId);
        List selectList = newsReadReportService.selectList(wrapper);
        PageInfo pageInfo = new PageInfo<NewsReadReportController>(selectList, 5);
        return ServiceResponse.createSuccessResponse(pageInfo);
    }
}

